package com.wego.common.base;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wego.common.constant.CommonConstant;
import lombok.Getter;
import lombok.Setter;

/**
 * @className: BaseQuery
 * @description: 查询基类
 * @author: Li Chuanwei
 * @date: 2023/07/10 12:20
 * @Company: Copyright [日期] by [作者或个人]
 **/

@Setter
public class BaseQuery<T> {
    private Integer pageNum;
    private Integer pageSize;

    @Getter
    private String keywords;

    public Page<T> toPage() {
        final Page<T> page = PageHelper.startPage(getPageNum(), getPageSize());
        return page;
    }

    public Integer getPageNum() {
        if (pageNum == null) {
            return CommonConstant.PAGE_NUM;
        }
        return pageNum;
    }

    public Integer getPageSize() {
        if (pageSize == null) {
            return CommonConstant.PAGE_SIZE;
        }
        return pageSize;
    }
}
